﻿using System;
using System.Windows.Data;
using System.Threading;

namespace JasonTools
{
    public class DateTimeToStringConverter : IValueConverter
    {
        object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                DateTime dt = (DateTime)value;
                string format = string.Empty;
                if (parameter!=null)
                {
                    format = (string)parameter;

                    if (format == "TODAY")
                    {
                        if (dt==DateTime.Today)
                        {
                            return "Today";// LocalizationResource.Today;
                        }
                        else
                        {
                            format = "MMMd";
                        }
                    }


                    var currentCulture = Thread.CurrentThread.CurrentCulture;
                    if (format.Contains("MMM")&&!format.Contains("MMMM")&&currentCulture.Name == "ko-KR")
                    {
                        format = format.Replace("MMM", "MMMM");
                    }
                    
                }
                return dt.ToString(format);
            }
            else
            {
                return string.Empty;
            }
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
